package freespiritsocial.io.user.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
import com.shuyu.gsyvideoplayer.GSYVideoManager
import freespiritsocial.io.user.R
import freespiritsocial.io.user.data.UserViewInfo
import freespiritsocial.io.user.ext.loadImage
import freespiritsocial.io.user.ui.fragment.post.ExplorePostDetailItemFrg
import freespiritsocial.io.user.util.video.SampleCoverVideo
import me.hgj.jetpackmvvm.util.StatusBarUtil

/**
 * @description
 * @author csw
 * @date 2022-01-21
 */
class PerViewVideoAct: AppCompatActivity() {
    companion object {
        fun launch(context: Context,b: UserViewInfo) {
            context.startActivity(Intent(context,PerViewVideoAct::class.java).putExtra("info",b))
        }
    }

    var videoPlayer: SampleCoverVideo? = null
    private val info by lazy(LazyThreadSafetyMode.NONE) {
        intent.getParcelableExtra<UserViewInfo>("info")
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        StatusBarUtil.immersive(this)
        setContentView(R.layout.activity_video)
        val videoPlayer = findViewById<SampleCoverVideo>(R.id.video_player)
        videoPlayer?.thumbImageView = ImageView(this).apply {
            loadImage(info?.videoUrl)
        }
        videoPlayer?.isVisible = true
        videoPlayer?.isLooping = true
        videoPlayer?.canToggleUI = true
        videoPlayer?.backButton?.isVisible = true
        videoPlayer?.setUpLazy(info?.videoUrl,true,null,null,"")
        videoPlayer?.backButton?.setOnClickListener {
            finish()
        }
        videoPlayer?.fullscreenButton?.isVisible = false
        //是否可以滑动调整
        videoPlayer?.setIsTouchWiget(false)
        videoPlayer?.playTag = ExplorePostDetailItemFrg.TAG
        videoPlayer?.startPlayLogic()
    }

    override fun onResume() {
        super.onResume()
        videoPlayer?.onVideoResume(false)
    }

    override fun onPause() {
        super.onPause()
        videoPlayer?.onVideoPause()
    }

    override fun onDestroy() {
        super.onDestroy()
        GSYVideoManager.releaseAllVideos()
    }
}